// sd_liferuning/pages/constmer/balance-recharge/index.js
var api = require("../../../../api.js"), app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    money: 0,
    balance: 0,
    account: ""
  },
  onLoad:function(e){
      this.setData({
        type:e.type,
      })
  },
  onShow:function(){
    var that = this;
    app.request({
      url: api.order.UpMoney,
      data: {
        uid: wx.getStorageSync('uid'),
        type:that.data.type
      },
      success: function (e) {
        console.log('=======',e)
        if (e.code == 1) {
          that.setData({
            balance: e.money
          })
        }
      }
    })
  },
  changeInputData: function (e) {
    let that = this;
    let inputName = e.currentTarget.dataset.name;
    let inputVlaue = e.detail.value;
    if (inputName == "money") {
      that.setData({
        money: inputVlaue
      });
    }
    if (inputName == "account") {
      that.setData({
        account: inputVlaue
      });
    }

  },
  sendRequest: function () {
    let _this = this;
    let _money = _this.data.money;
    let _balance = _this.data.balance;
    let _account = _this.data.account;
    if (_account == "") {
      wx.showToast({
        title: '支付宝账号不得为空',
        icon: 'none'
      })
      return false;
    }
    if (_money > _balance || _money == "" || _money==0) {
      wx.showToast({
        title: '请正确填写金额',
        icon: 'none'
      })
      return false;
    }
    console.log(_money,_balance,_account)
    // TODO 执行请求
    app.request({
      url: api.order.alipaySend,
      data: {
        uid: wx.getStorageSync('uid'),
        bid: wx.getStorageSync('bid'),
        money:_money,
        name: wx.getStorageSync('nickname'),
        alipay: _account,
        type: _this.data.type
      },
      success: function (e) {
        wx.showToast({
          title: '提现成功!！',
          icon: 'none',
          duration: 2000,
        })
        if (_this.data.type == 1){
          wx.navigateTo({
            url: '/sd_liferuning/pages/constmer/balance-management/index'　　// 页面 A
          })
        }else{
          wx.navigateTo({
            url: '/sd_liferuning/pages/service/balance-management/index'　　// 页面 A
          })
        }
      }
    })
  }
})